package de.baumann.browser.present

import de.baumann.browser.api.OdinObserver
import de.baumann.browser.api.net.vo.NodeStatus
import de.baumann.browser.base.BasePresenter
import de.baumann.browser.iview.INodeStatusView
import de.baumann.browser.model.NodeModel

class NodeStatusPresenter : BasePresenter<INodeStatusView>() {
    fun nodeStatus(nodeId: String) {
        NodeModel().nodeStatus(nodeId)
                .subscribe(object : OdinObserver<NodeStatus>(view) {
                    override fun onSuccess(data: NodeStatus?) {
                        if (view == null || data == null) {
                            return
                        }
                        val node = data.nodeInfo ?: return

                        view.setNodeName(node.nodeName)
                        view.setNodeMembers(String.format("人数(%s)", node.headcount))
                        view.setNodeOwner(node.ownerName)
                        view.setOwnerId(node.creatBy)
                        view.setCreateTime(node.createTime)
                        view.setTotalHash(node.totalContribute)
                        view.setNodeProgress(data.applyFormatList)
                        view.setNodeDesc(node.remake)
                        view.setHead(node.ownerAvatar)
                    }
                })
    }
}